package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.StartupImages;
import com.amigo.online.provider.manager.service.StartupImagesService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/startupImages", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class StartupImagesController extends BaseController {

    @Resource
    private StartupImagesService startupImagesService;


    @PostMapping(value = "/getstartupImagesList")
    public ResponseEntity<Response> getstartupImagesList(@RequestBody StartupImages startupImages) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(startupImages.getPageNo(), 10);

        List<StartupImages> startupImageslist = startupImagesService.findStartupImagesList(startupImages);
        result.put("startupImageslist", startupImageslist);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    /**
     * 添加启动图
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/insertionStartupImages")
    public ResponseEntity<Response> insertionStartupImages(@RequestBody StartupImages startupImages) {
        //System.out.println(startupImages);
        return success(startupImagesService.insertionStartupImages(startupImages));

    }


    /**
     * 修改启动图
     *
     * @param data
     * @return
     */
    @PutMapping(value = "/updateStartupImages")
    public ResponseEntity<Response> updateUser(@RequestBody StartupImages startupImages) {
        return success(startupImagesService.updateStartupImages(startupImages));

    }


    /**
     * 删除启动图
     *
     * @param data
     * @return
     */
    @DeleteMapping(value = "/deleteStartupImages")
    public ResponseEntity<Response> deleteStartupImages(@RequestBody StartupImages startupImages) {
        return success(startupImagesService.deleteStartupImages(startupImages));

    }


}
